import type { ComputedRef } from 'vue';
import { BasicTableProps } from '/@/components/BasicTable/type/BasicTableProps';
import { computed, ref, unref } from 'vue';
import { isBoolean } from '/@/utils/is';

export function usePagination(paramProps: ComputedRef<BasicTableProps>) {
  const configRef = ref({});
  const pagination = computed(() => {
    const { usePagination } = unref(paramProps);
    if (!isBoolean(usePagination) || !usePagination) {
      return;
    }
    return {
      showSizeChanger: false,
      showQuickJumper: true,
      current: 1,
      size: 10,
      showTotal: (total: any) => {
        return `共 ${total} 条`;
      },
      ...unref(configRef),
    };
  });

  function setPagination(info: any) {
    configRef.value = {
      ...info,
    };
  }

  async function getPagination() {
    return unref(pagination);
  }

  return {
    getPagination,
    setPagination,
    pagination,
  };
}
